<?php
class RoleAction extends BaseAction {
	
	function index(){
		
		$role = d("role_info");
		$r_arr = $role->findall();
		foreach ($r_arr as $key=>$value){
				foreach ($value as $k=>$v){
					$arr[] = $v;
				}
				$arr2[] = $arr;
				$arr = "";
		}
		
		$this->assign('role_arr',$arr2);
		//dump($arr2);
		$this->display("Role:role_list");
	}
	
	function Role_edit(){
		
		$roles_name = $_POST['roles_row'];	
		//echo $op."<br />";
		if($_POST['oper']){
			foreach ($roles_name as $value){
				$str = $value."_result";
				//echo $str."<br />";
				$arr = explode(",",$_POST["$str"]);
				//echo $str." : ".$this->spArgs("$str","")."<br>";
				
				$roles_arr['view'] = $arr['0'];
				$roles_arr['publish'] = $arr['1'];
				$roles_arr['edit'] = $arr['2'];
				$roles_arr['verify'] = $arr['3'];
				$roles_arr['del'] = $arr['4'];
				$roles_arr['admin'] = $arr['5'];
				$condition = "Role_name = '".$value."'";
				//print_r($roles_arr);
				//echo $condition;
				d("role_info")->where($condition)->save($roles_arr);
				$roles_arr = "";
			}
			
			$this->success("角色修改成功!");
		}
	}
	
	function Role_del(){
		if($_POST['oper']){
			$roles_str = implode("','",$_POST['roles_row']);
			//echo "Role_name in ('".$roles_str."')";
			d("role_info")->where("Role_name in ('".$roles_str."')")->delete();
			$this->success("角色删除成功!");
		}
	}	
			
	function Role_add(){		
		
		if($_POST['oper']){
			
			$new_arr = explode(",",$_POST['new_auth']);
			
			$roles_arr['Role_name'] = $_POST['new_name'];	
			$roles_arr['view'] = $new_arr['0'];
			$roles_arr['publish'] = $new_arr['1'];
			$roles_arr['edit'] = $new_arr['2'];
			$roles_arr['verify'] = $new_arr['3'];
			$roles_arr['del'] = $new_arr['4'];
			$roles_arr['admin'] = $new_arr['5'];
			d("role_info")->add($roles_arr);
			$this->success("角色增加成功!");
			//dump($roles_arr);
		}
	}
}




?>